var dao = require('./dao')
const { json } = require('express')

var userDAL = {
    login:function(users,cb){
        var sql = 'select * from user where uid=? and password=?'
        var params=[users.userName,users.userpassword]
        console.log(params)
        dao(sql, params, function (err, results) {
            if (err) {
                console.log('没查到')
                cb(err, null)
            } else {
                console.log('查到了')
                cb(null, results)
            }
        }) 
    },
    register:function(users,cb){
        // console.log('1')
        var sql = 'insert into user(uId,password,tel) value(?,?,?)'
        // console.log(users)
        var params = [users.userName,users.userpassword,users.usertel]
        // console.log(params)
        dao(sql, params, function (err, results) {
            if (err) {
                // console.log('1')
                cb(err, null)
            } else {
                // console.log('2')
                cb(null, results)
            }
        })
    },
    checkName:function(users,cb){
        var sql = 'select * from user where uId = ?'
        console.log(users)
        var params = [users.userName]
        console.log(params)
        dao(sql, params, function (err, results) {
            if (err) {
                cb(err, null)
            } else {
                cb(null, results)
            }
        })
    }
}
module.exports = userDAL